#nullable enable
namespace Wips.Domain.Models.Authorities.Model
{
    /// <summary>
    /// 菜单
    /// </summary>
    [Table("AuthorityMenus")]
    [SugarTable("AuthorityMenus", "功能菜单")]
    public class Menu : EntityBase, IAggregateRoot
    {

        /// <summary>
        /// 父级ID
        /// </summary>
        [MaxLength(36)]
        public string? ParentId { get; set; }

        /// <summary>
        /// 上级路径，用逗号分割，用于快速检索
        /// </summary>
        [MaxLength(500)]
        public string? ParentPath { get; set; }

        /// <summary>
        /// 名称
        /// </summary>
        [Required]
        [MaxLength(12)]
        public string? Name { get; set; } = "";

        /// <summary>
        /// 图标
        /// </summary>
        [MaxLength(50)]
        public string? Icon { get; set; } = "";

        /// <summary>
        /// 跳转路径
        /// </summary>
        [MaxLength(512)]
        public string? Path { get; set; } = "";


        /// <summary>
        /// 排序
        /// </summary>
        public int Sort { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public Status Status { get; set; }

        /// <summary>
        /// 是否在数据行操作上的菜单
        ///     类型为菜单专用字段，因为有部分菜单是嵌入数据行里的
        ///     如果该值为true,将不显示在左侧导航菜单和头部导航菜单
        /// </summary>
        public bool IsInside { get; set; }


        /// <summary>
        /// 最后更新人Id
        /// </summary>
        [MaxLength(36)]
        public string LastUpdatedUserId { get; set; } = "";


        /// <summary>
        /// 操作
        /// </summary>
        [Navigate(NavigateType.OneToMany, nameof(Operation.MenuId))]
        public List<Operation> Operations { get; set; } = null!;

        /// <summary>
        /// 状态变更
        /// </summary>
        /// <param name="lastUpdatedUserId"></param>
        public void StatusChange(string lastUpdatedUserId)
        {
            Status = Status == Status.Disabled ? Status.Enabled : Status.Disabled;
            LastUpdatedUserId = lastUpdatedUserId;
            Updated = DateTime.Now;
        }
    }
}